<style>
	.CGridViewContainer { 
		width: 1000px;   
		overflow: auto;    
		scrollbar-base-color:#ffeaff 
	}
</style>
<script>var id_keg = '<?php echo $model->id_kegiatan; ?>';</script>
<div class="form">
<?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm',array(
	'id'=>'kegiatan-form',
	'enableAjaxValidation'=>true,
        'method'=>'post',
	'type'=>'horizontal',
	'htmlOptions'=>array(
		'enctype'=>'multipart/form-data'
	)
)); ?>
     	<fieldset>
		<legend>
			Kegiatan Detil
		</legend>

	<?php echo $form->errorSummary($model,'Opps!!!', null,array('class'=>'alert alert-error span12')); ?> 
	<?php
		$modelTim  = new TimExtend;
		$iterator = new CDataProviderIterator($modelTim->editKegiatan($model->id_kegiatan));
		$total = '';
		foreach ($iterator as $val){
			$harian = intval($val->biaya_harian)*intval($val->hari);
			$penginapan = intval($val->biaya_penginapan)*intval($val->hari);
			$biaya_trans = intval($val->biaya_trans);
			$airportax = intval($val->airportax);
			$riil = intval($val->riil);
			$total += $harian+$penginapan+$biaya_trans+$airportax+$riil;
			
		}
		if($model->anggaran)$model->anggaran = Yii::app()->spd->moneyFormat($model->anggaran);
		if($total)$total = Yii::app()->spd->moneyFormat($total);
	?>
   <div class="control-group">		
			<div class="span4" style="width:100%">
				<div class="formSidel">
					<?php echo $form->textFieldRow($model,'no_keg',array('class'=>'span5','maxlength'=>45)); ?>
					<?php echo $form->textFieldRow($model,'nama_kegiatan',array('class'=>'span5','maxlength'=>45)); ?>
					
				</div>
				<div class="formSider">
					<?php echo $form->textFieldRow($model,'anggaran',array('class'=>'span5 moneyFormat','prepend'=>'Rp','append'=>',00')); ?>
					<?php echo $form->textAreaRow($model,'description',array('rows'=>6, 'cols'=>50, 'class'=>'span8')); ?>
				</div>
			</div>   
  </div>

	<div class="form-actions">
		<?php $this->widget('bootstrap.widgets.TbButton', array(
			'buttonType'=>'submit',
			'type'=>'primary',
                        'icon'=>'ok white',  
			'label'=>$model->isNewRecord ? 'Create' : 'Save',
		)); ?>
              <?php $this->widget('bootstrap.widgets.TbButton', array(
			'buttonType'=>'reset',
                        'icon'=>'remove',  
			'label'=>'Reset',
		)); ?>
	</div>
</fieldset>

<?php $this->endWidget(); ?>


</div>
<div class="form">
<?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm',array(
	'id'=>'kegiatan-sss','type'=>'horizontal',
)); ?>
<fieldset>
	<legend>
			Tim List
	</legend>
	<div style="padding-left:10px;padding-right:10px;margin-bottom:20px;">
		
		<?php
		echo '<div class="alert" style="padding-top:20px">
				Total Biaya : <br/><br/>
				<div class="input-prepend input-append" >
				<span class="add-on">Rp</span>
					<input id="totalBiaya" class="span5" type="text" value="'.$total.'" name="totalBiaya">
				<span class="add-on">,00</span>
			</div><br/><br/></div>';
		$this->widget('bootstrap.widgets.TbButton', array(
			
			'label'=>'Add Tim',
			'type'=>'primary',
			'htmlOptions'=>array(
				'id'=>'addtim',
				'data-toggle'=>'modal',
				'data-target'=>'#timAdd',
			),
		));?>
		<div class="CGridViewContainer">
		<?php
		$this->widget('bootstrap.widgets.TbGridView',array(
				'id'=>'tim-grid',
				'dataProvider'=>$modelTim->editKegiatan($model->id_kegiatan),
					'type'=>'striped bordered condensed',
					'template'=>'{summary}{pager}{items}{pager}',
					'htmlOptions'=>array('style'=>'width: 1500px'),
				'columns'=>array(
					array(
						'header'=>'No.',
						'value'=>'$this->grid->dataProvider->pagination->currentPage * $this->grid->dataProvider->pagination->pageSize + ($row+1)',
					  ),
					array(
						'header' => 'NIP',
						'name' => 'nip',
						'value' => '$data->nip',
					),
					array(
						'header' => 'Nama',
						'name' => 'nama',
						'value' => '$data->nama',
					),
					array(
						'header' => 'Provinsi',
						'name' => 'nama_prov',
						'value' => '$data->nama_prov',
					),
					array(
						'header' => 'Cost PerDay',
						'name' => 'biaya_harian',
						'value' => 'Yii::app()->spd->moneyFormat($data->biaya_harian)',
					),
					array(
						'header' => 'Cost Staying',
						'name' => 'biaya_penginapan',
						'value' => 'Yii::app()->spd->moneyFormat($data->biaya_penginapan)',
					),
					array(
						'header' => 'Armada',
						'name' => 'description',
						'value' => '$data->description',
					),
					array(
						'header' => 'Biaya_trans',
						'name' => 'biaya_trans',
						'value' => 'Yii::app()->spd->moneyFormat($data->biaya_trans)',
					),
					array(
						'header' => 'Airportax',
						'name' => 'airportax',
						'value' => 'Yii::app()->spd->moneyFormat($data->airportax)',
					),
					array(
						'header' => 'Riil',
						'name' => 'riil',
						'value' => 'Yii::app()->spd->moneyFormat($data->riil)',
					),
					array(
						'header' => 'Tgl Mulai',
						'name' => 'tgl_mulai',
						'value' => '$data->tgl_mulai',
					),
					array(
						'header' => 'Tgl Akhir',
						'name' => 'tgl_berakhir',
						'value' => '$data->tgl_berakhir',
					),
					array(
						'header' => 'Hari',
						'name' => 'hari',
						'value' => '$data->hari',
					),
				   array(
						'class'=>'bootstrap.widgets.TbButtonColumn',
						'template' => '{update} {delete} {view}',
						'buttons' => array(
							  'view' => array(
								'label'=> 'Cetak',
								'url' => 'Yii::app()->controller->createUrl("kegiatan/winCetak", array("id" => $data->id_tim))',
								'icon'=>'icon-print',
								'options'=>array(
									'class'=>'btn btn-small view',
									'data-target' => "#winCetak",
									'data-toggle' => "modal"
								),
								'click'=>"function(){
										var actCetak = $(this).attr('href');  
										$('#timAdd').html('');
										$('#timEdit').html('');
										$('#winCetak').load(actCetak);
									}",
							),	
							'update' => array(
								'label'=> 'Update',
								'url' => 'Yii::app()->controller->createUrl("tim/update", array("id_kegiatan" => $data->id_kegiatan,"id" => $data->id_tim))',
								'click'=>"function(){
										var action = $(this).attr('href');  
										$('#timAdd').html('');
										$('#winCetak').html('');
										$('#timEdit').load(action);
									}",
								'options'=>array(
									'class'=>'btn btn-small update',
									'data-target' => "#timEdit",
									'data-toggle' => "modal"
								),
							),
							'delete' => array(
								'label' => 'Delete',
								'url' => 'Yii::app()->controller->createUrl("tim/deleteKeg", array("id" => $data->id_tim))',
								'click'=>"function(){
									if (confirm('Are you sure you want to delete')) {
											var form_action = $(this).attr('href');  
											var form_method = 'POST';  
											$.ajax( {  
												type :form_method,  
												url :form_action,  
												cache :false,  
												success : function(data) {  	
													alert('Data Has Been Deleted');						
													window.location.href = '';								
												},  
												error : function() {  
													alert('Failed to load data');  
												}  
											});
										  }
										return false;
									}",
								'options' => array(
									'class' => 'btn btn-small delete'
								)
							),  
						),
						'htmlOptions'=>array('style'=>'width: 115px'),
					   )
				),
			)); 
		?>
	</div>
	</div>
    
</fieldset>

<?php $this->endWidget(); ?>


</div>
<?php $this->beginWidget('bootstrap.widgets.TbModal', array(
			'id'=>'timAdd',
			'htmlOptions'=>array('style'=>'width:800px'),
)); ?>
<?php $this->endWidget(); ?>
<?php $this->beginWidget('bootstrap.widgets.TbModal', array(
			'id'=>'timEdit',
			'htmlOptions'=>array('style'=>'width:800px'),
)); ?>
<?php $this->endWidget(); ?>
<?php $this->beginWidget('bootstrap.widgets.TbModal', array(
			'id'=>'winCetak',
			'htmlOptions'=>array('style'=>'width:800px'),
)); ?>
<?php $this->endWidget(); ?>
<script src="<?php echo Yii::app()->baseUrl; ?>/addon/js_modul/kegiatan/kegiatan.js"></script>